import axios from "axios";

export default {
  namespaced: true,
  state: {
    bottomListData:[],
    movieIdList:[],
    loading:false,
    i:10
  },
  mutations: {
    setLoading(state,payload){
      state.loading=payload;
    },
    setbottomListData(state, data){
        state.bottomListData = data; 
    },

    setMorebottomListData(state,data){
      state.bottomListData=[...state.bottomListData,...data];
    },
    setmovieIdList(state,data){
        state.movieIdList=data;
    }
  },
  actions: {

    async requestresetListData(context,payload){
      this.state.homeList.i=10;
        const {data:{data}}
        =await axios.get(
        "/data/index.json"
      );
      const result=data.splice(0,10);
      context.commit("setmovieIdList",data);
      context.commit('setbottomListData', result);
    },

    


    async requestMoreListData(context, payload){
      // 请求数据
      context.commit('setLoading', true);
      const {data:{data}}=await axios.get('/data/index.json');
      const comings=data.splice(this.state.homeList.i,10);
      this.state.homeList.i=20;
      context.commit('setMorebottomListData',comings);
      // console.log(this.state.homeList.bottomListData.length);
      context.commit('setLoading', false);
    }
  }
}